from config import Config
from parsers.elf import ELF


class FileData(object):
    def __init__(self):
        pass

    def initdata(self,filename):
        file = open(filename, "rb")
        self.file_data = file.read()
        file.close()
        self.filetype()

    def filetype(self):
        if self.file_data.hex()[0:4] == "4d5a":
            Config.instance().QtUI.databack(0,"PE文件")
        if self.file_data.hex()[0:8] == "7f454c46":
            Config.instance().QtUI.databack(0,"ELF文件")
            ELF(self.file_data)
        else:
            Config.instance().QtUI.databack(0,"其它文件")

    @classmethod
    def instance(cls, *args, **kwargs):
        if not hasattr(FileData, "_instance"):
            FileData._instance = FileData(*args, **kwargs)
        return FileData._instance


    def __del__(self):
        pass


